﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using WcfServiceLibrary1;

namespace WCF_Host_App
{
    public partial class Form1 : Form
    {
        ServiceHost vHost;
        public Form1()
        {
            InitializeComponent();
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            try
            {
                vHost = new ServiceHost(typeof(Service1));
                NetTcpBinding b = new NetTcpBinding();
                b.Security.Mode = SecurityMode.Message;
                b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

                vHost.AddServiceEndpoint(typeof(IService1), b ,new Uri("net.tcp://193.225.227.148/myservice"));
                vHost.Open();
                button_start.Enabled = false;
                button_stop.Enabled = true;
                label_statusinfo.Text = "Service Started";

                MessageBox.Show("Service started");
            }

            catch (Exception ex)
            {
                label_statusinfo.Text = ex.Message.ToString();
            }

        }

        private void button_stop_Click(object sender, EventArgs e)
        {
            vHost.Close();
            label_statusinfo.Text = "Service stopped";
            button_stop.Enabled = false;
            button_start.Enabled = true;
        }
    }
}
